/*
 * @Description: 
 * @Author: 邢
 * @Date: 2021-04-22 14:59:23
 * @LastEditTime: 2021-05-05 19:21:08
 * @LastEditors: 邢
 */
//引入mobx仓库创建函数
import { makeAutoObservable } from "mobx";

//引入request请求接口
import { getAllBooks, getBookItem, getLikes,setLikes } from "@/seivers/cooran"
//引入ts接口文档
import { Iallbooks, IbookItem, RootObject } from "@/utils/interface/cooran"

//制作类
class Cooran{
    constructor(){
        makeAutoObservable(this);
    };
    //初始化数据
    allBooks:Iallbooks[] = [];
    bookItem:IbookItem = {};
    bookText:IbookItem = {};
    liks:RootObject = {} as RootObject
    //同步&异步方法
    async getAllBooks(){
        let result = await getAllBooks();
        if(result.statusCode === 200){
            this.allBooks = result.data[0]
        }
    }
    async getBookItem(id:string){
        let result = await getBookItem(id);
        if(result.statusCode === 200){
            this.bookItem = result.data
        }
    }
    async getBookText(id:string){
        let result = await getBookItem(id);
        if(result.statusCode === 200){
            console.log("text",result.data)
            this.bookText = result.data
        }
    }
    async getLikes(id:string){
        let result = await getLikes(id);
        if(result.statusCode === 200){
            this.liks = result.data
        }
    }
    //点击喜欢
    async setLikes(id:string,type:string){
        console.log("model",id)
        let result = await setLikes(id,type);
        if(result.statusCode === 200){
            if(type){
                console.log("取消喜欢成功！！！")
            }else{
                console.log("喜欢成功！！！")
            }
        }
    }

}

export default Cooran